{include file="Include/H_ui_head" /}
<article class="page-container">
	<form  class="form form-horizontal" id="form-member-add" enctype="multipart/form-data">
		<input type="hidden" name="good_id" id="good_id" class="input-text" value="{$res.good_id}" />
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$res.good_name}" placeholder="" id="good_name" name="good_name">
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片：</label>
			<div class="formControls col-xs-8 col-sm-9">
					<input type="button" value="上传图片" onclick="f.click()" class="btn btn-primary radius"/><br>
					<p><input type="file" id="f" name="f" onchange="sc(this);" style="display:none"/></p>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片预览：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<img src="{$res.good_img}" alt="">
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>库存：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$res.inventory}" placeholder="" id="inventory" name="inventory">
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>一级代理价格：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$res.one_money}" placeholder="" id="one_money" name="one_money">
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>二级代理价格：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$res.two_money}" placeholder="" id="two_money" name="two_money">
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>三级代理价格：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$res.three_money}" placeholder="" id="three_money" name="three_money">
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>分公司价格：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$res.company_money}" placeholder="" id="company_money" name="company_money">
			</div>
		</div>
		
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" type="button"  onclick="return goods_add()"  value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>

{include file="Include/H_ui_foot" /}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__LIB__/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__STATIC__/common.js"></script>
<script type="text/javascript">
/*用户-停用*/
function goods_add(obj,id){
    var id = $("[name='m_id']").val();
    var url = "{:url('Goods/goods_edit')}";

    var params =getParams(".input-text")

    var loading =layer.msg('正在提交数据，请稍后...',{time:5000});
    $.post(url,params,function(data){
        layer.close(loading);
        if(data.code=='1'){
            layer.msg(data.msg,{time:2000});
            setTimeout(function(){
                layer_close(this.index);
                parent.location.reload();
            },1000);
        }else{
            layer.msg(data.msg,{time:2000});
        }
    });
}

function sc(){
    var animateimg = $("#f").val(); //获取上传的图片名 带//
    var imgarr=animateimg.split('\\'); //分割
    var myimg=imgarr[imgarr.length-1]; //去掉 // 获取图片名
    var houzui = myimg.lastIndexOf('.'); //获取 . 出现的位置
    var ext = myimg.substring(houzui, myimg.length).toUpperCase();  //切割 . 获取文件后缀
    
    var file = $('#f').get(0).files[0]; //获取上传的文件
	// console.log(file);
    var fileSize = file.size;           //获取上传的文件大小
    var maxSize = 1048576;              //最大1MB
    if(ext !='.PNG' && ext !='.GIF' && ext !='.JPG' && ext !='.JPEG' && ext !='.BMP'){
        parent.layer.msg('文件类型错误,请上传图片类型');
        return false;
    }else if(parseInt(fileSize) >= parseInt(maxSize)){
        parent.layer.msg('上传的文件不能超过1MB');
        return false;
    }else{  
        
		// console.log(data);
		// var good_img = animateimg;
	var data = new FormData($("#form-member-add"));
	console.log(data);
	data.append('good_img',file);
        $.ajax({  
            url: "{:Url('Goods/img')}", 
            type: 'POST',  
            data: FormData,  
            dataType: 'JSON',
        }).done(function(ret){  
            if(ret['isSuccess']){
                var result = '';
                var result1 = '';
                // $("#show").attr('value',+ ret['f'] +);
                result += '<img src="' + '__ROAD__' + ret['f']  + '" width="100">';
                result1 += '<input value="' + ret['f']  + '" name="user_headimg" style="display:none;">';
                $('#result').html(result);
                $('#show').html(result1);
                layer.msg('上传成功');
            }else{  
                layer.msg('上传失败');
            }  
        });  
        return false;
       }  
    }


function append_img()
{
	var img = $("#good_img").val();
	var url = "{:Url('Goods/img')}";
	$.post(url,img,function(data){
        if(data.code=='1'){
            layer.msg(data.msg,{time:2000});
            setTimeout(function(){
                layer_close(this.index);
                parent.location.reload();
            },1000);
        }else{
            layer.msg(data.msg,{time:2000});
        }
    });
}
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
